package com.sun.showcase.controller.app.mall;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sun.showcase.biz.mall.service.FreightDetailService;
import com.sun.showcase.client.vo.FreightFeeQueryEntity;
import com.sun.showcase.pojo.Result;
@CrossOrigin
@RestController("appFreightController")
@RequestMapping(value="/app/freight") 
public class FreightController{
	
	@Autowired
	private FreightDetailService freightDetailService;
	
	private Result result = new Result();
	
	@RequestMapping(value="getFee")
	public Result getFee(@RequestBody @Valid List<FreightFeeQueryEntity> info,
			BindingResult bindingResult) {
		if(bindingResult.hasErrors()) {
			result.setSuccess(false);
			result.setMsg(bindingResult.getFieldError().getDefaultMessage());
			return result;
		}
		Double fee = freightDetailService.getFreightFee(info);
		result.setSuccess(true);
		result.setData(fee);
		return result;
	}
}
